#
# @lc app=leetcode.cn id=860 lang=python
#
# [860] 柠檬水找零
#

# @lc code=start
from collections import defaultdict
class Solution(object):
    def lemonadeChange(self, bills):
        """
        :type bills: List[int]
        :rtype: bool
        """
        billdict = defaultdict(int)
        for i in range(len(bills)):
            if bills[i] == 5:
                billdict['5'] += 1
            elif bills[i] == 10:
                billdict['5'] -= 1
                if billdict['5'] <0:
                    return False
                billdict['10'] += 1
            else:
                if billdict['10'] > 0:
                    billdict['10'] -= 1
                    billdict['5'] -= 1

                elif billdict['10'] == 0:
                    billdict['5'] -= 3

                if billdict['5'] < 0:
                    return False
        return True


# @lc code=end

